﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TGInspect
{
    public enum MCStatus
    {
        INIT = 0,
        START = 10,
        /// <summary>
        /// Home Status
        /// </summary>
        SV_GO_CW_SENSOR = 100,
        SV_GO_CCW_SENSOR,
        SV_GO_ORG_SENSOR,
        SV_STOP_CW_SENSOR,
        SV_STOP_CCW_SENSOR,
        SV_STOP_ORG_SENSOR,
        SV_OUT_CW_SENSOR,
        SV_OUT_CCW_SENSOR,
        SV_OUT_ORG_SENSOR,
        SV_LOOK_Z_PHASE,
        SV_END_POS_SET,
        SV_HOME_END,
       
        ERROR = 999,
        STOP,
        IDLE,
    }


    public class Status 
    {
        RtTimer Delay;
        MCStatus nowStatus;
        MCStatus PastStatus;
        public bool Init { get; private set; }
        public bool Error { get; private set; }
        public bool Run
        {
            get { return (MCStatus.STOP == nowStatus); }
        }
        public MCStatus NowStatus 
        { 
            get { return nowStatus; } 
            set 
            { 
                nowStatus = value;
                switch (nowStatus)
                {
                    case MCStatus.INIT  : Init = false; break;
                    case MCStatus.START: Init = true; break;
                    case MCStatus.ERROR: Error = true; break;
                    case MCStatus.STOP: break;
                }
                if (nowStatus != PastStatus)
                    Delay.SetTime();
                    
            } 
        }

        public Status()
        {
            Init = false;
            Error = false;
            NowStatus = PastStatus = MCStatus.STOP;
            Delay = new RtTimer();
        }

        public void SetDelay()
        {
            Delay.SetTime();
        }

        public bool DelayMs(uint mSec)
        {
            return Delay.IsTimeOverMs(mSec);
        }

        public uint ElapseMs()
        {
            return Delay.GetElapsedTimeMs();
        }
    }
}
